LearningStoreJob Class

Represents a job that can be executed by a store

Namespace: Microsoft.LearningComponents.Storage

Assembly: Microsoft.LearningComponents.Storage.dll

Syntax
C#

public class LearningStoreJob

Methods
Name Description
Ð AddItem (string, IDictionary<string,object>)

Add a new item

Ð AddItem (string, IDictionary<string,object>, bool)

Add a new item to a store.

Ð AddOrUpdateItem (string, IDictionary<string,object>, IDictionary<string,object>)

Add an item, or update the item properties if the item already exists

Ð AddOrUpdateItem (string, IDictionary<string,object>, IDictionary<string,object>, IDictionary<string,object>)

Add an item, or update the item properties if the item already exists

Ð AddOrUpdateItem (string, IDictionary<string,object>, IDictionary<string,object>, IDictionary<string,object>, bool)

Add an item, or update the item properties if the item already exists

Ð DeleteItem

Delete an item

Ð DemandRight (string)

Demand a right. When the job is executed, the job will be aborted unless the current user has the specified right.

Ð DemandRight (string, IDictionary<string,object>)

Demand a right. When the job is executed, the job will be aborted unless the current user has the specified right.

Ð DisableFollowingSecurityChecks

Disable security checks for the operations added to the job after this call.

Ð EnableFollowingSecurityChecks

Enable security checks for the operations added to the job after this call.

Ð Execute ()

Execute the commands in the job

Ð Execute<T> ()

Execute the commands in the job.

Ð PerformQuery

Perform a query

Ð UpdateItem

Update properties on an item

Remarks

A job is a collection of operations that can be performed on a store. All of the operations are executed as a batch, and if any of the operations fail, then the entire job fails. To create and execute a job, perform the following steps:

  1. Create a new LearningStoreJob on a store by calling LearningStore.CreateJob.
  2. Call methods on the LearningStoreJob to add operations to the job. The operations will be executed in the order in which they are added to the job.
  3. Call Execute on the job to execute it. The results of the job are returned.

Here's some example code that adds a new user to a store:

C#
// Create the job
LearningStoreJob job = store.CreateJob();
 
// Add the "add" operation
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
job.AddItem("UserItem", propertyValues);
 
// Execute the job
job.Execute();
Multiple operations can be performed in the same job. For example, here's some code that adds a new user, a new global objective, and a new learner global objective:
C#
// Create the job
LearningStoreJob job = store.CreateJob();

// Add the first "add" operation that adds the user
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
LearningStoreItemIdentifier newUserId = job.AddItem("UserItem", propertyValues);

// Add the second "add" operation that adds the global objective
propertyValues = new Dictionary<string,object>();
propertyValues["Key"] = "MyGlobalObjective";
propertyValues["Description"] = "MyGlobalObjective Description";
LearningStoreItemIdentifier newGlobalObjectiveId = job.AddItem("GlobalObjectiveItem", propertyValues);

// Add the third "add operation" that adds the learner global objective
propertyValues = new Dictionary<string,object>();
propertyValues["LearnerId"] = newUserId;
propertyValues["GlobalObjectiveId"] = newGlobalObjectiveId;
job.AddItem("LearnerGlobalObjectiveItem", propertyValues);
 
// Execute the job, which adds all the items
job.Execute();
Operations in a job may return results. For example, the "add item" operation, with the correct parameters, can return the Id of the added item. If multiple operations are added to a job, the results are returned in the order of the operations performed. Example:
C#
// Create the job
LearningStoreJob job = store.CreateJob();

// Add the first "add" operation that adds the user
Dictionary<string,object> propertyValues = new Dictionary<string,object>();
propertyValues["Name"] = "John Doe";
propertyValues["Key"] = "Company\JohnDoe";
LearningStoreItemIdentifier newUserId = job.AddItem("UserItem", propertyValues, true); // passing true forces the operation to return the Id of the new item in the store in the results

// Add the second "add" operation that adds the global objective
propertyValues = new Dictionary<string,object>();
propertyValues["Key"] = "MyGlobalObjective";
propertyValues["Description"] = "MyGlobalObjective Description";
LearningStoreItemIdentifier newGlobalObjectiveId = job.AddItem("GlobalObjectiveItem", propertyValues);  

// Add the third "add operation" that adds the learner global objective
propertyValues = new Dictionary<string,object>();
propertyValues["LearnerId"] = newUserId;
propertyValues["GlobalObjectiveId"] = newGlobalObjectiveId;
job.AddItem("LearnerGlobalObjectiveItem", propertyValues, true); // passing true forces the operation to return the Id of the new item in the store in the results
 
// Execute the job, which adds all the items
ReadOnlyCollection<object> results = job.Execute();
After the code above is executed, results[0] contains the Id of the user (the first operation that returns a result), and results[1] contains the Id of the learner global objective (the second operation that returns a result). See the specific methods for more information about what results are returned (e.g., see the AddItem method for more information about the results that are returned when adding an item).

See the Execute method documentation for more information about executing jobs, including information about how jobs interact with transactions.